package kt_test.ui.activity

import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kt_test.model.OxygenUploadRequest
import kt_test.network.OxygenUploader
import kt_test.util.JsonLoader
import com.example.healthapp.R

class TestUploadActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_upload) // ← layout 文件要有这个名字


        val button = findViewById<Button>(R.id.btn_upload_test)

        button.setOnClickListener {
            val data: OxygenUploadRequest? = JsonLoader.loadOxygenData(this)

            if (data != null) {
                OxygenUploader.uploadData(
                    data,
                    onSuccess = {
                        runOnUiThread {
                            Toast.makeText(this, "上传成功", Toast.LENGTH_SHORT).show()
                        }
                    },
                    onFailure = { error ->
                        runOnUiThread {
                            Toast.makeText(this, "上传失败: $error", Toast.LENGTH_LONG).show()
                        }
                    }
                )
            } else {
                Toast.makeText(this, "加载数据失败", Toast.LENGTH_SHORT).show()
            }
        }
    }
}
